<?php
namespace Home\Controller;
use Think\Controller;
class FabuquController extends Controller {
    public function pp(){
$search=M('search');//实例化news对象
$this->lostnum=$search->count();
$lostnumover=$search->where("isfinish=1") ->count();
$this->all=$lostnumover+$findnumover;
$this->lostno=$search->where("isfinish=0") -> order('isfirst desc, id desc') ->limit() ->select();
        $userInfo = M('users');
        $data['telephone']=$_SESSION['telephone'];
        $userInfo = $userInfo->where($data)->find();
        $this->userInfo=$userInfo;

      
      $this->display();
 }
    public function detail(){
        $data["id"]=I('get.id');
        $this->goodsDetail=M("goods")->where($data)->find();
        $this->display();
    }

  public function release(){
  $user = M('users');
  $data['telephone']=$_SESSION['telephone'];
  $res = $user->where($data)->find();
  $this->userInfo=$res;
  $this->display();
  }

      public function MyUpload(){
          $upload = new \Think\Upload();// 实例化上传类
          $upload->maxSize   =     3145728 ;// 设置附件上传大小
          $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
          $upload->rootPath  =     './Public/Uploads/search/'; // 设置附件上传根目录  //  $upload->autoSub = false;//关闭子目录，默认true
          $upload->autoSub = false;
         /* $upload->savePath  =     ''; */// 设置附件上传(子)目录，默认目录名为年月日
                  $info   =   $upload->upload();  // 上传文件 
              if(!$info) {     
                //上传错误提示错误信息
                 $this->error($upload->getError());   
                  }
              else{        
              return $info;
                 }                   
                 }
     public function MUpload(){
          $upload = new \Think\Upload();// 实例化上传类
          $upload->maxSize   =     3145728 ;// 设置附件上传大小
          $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
          $upload->rootPath  =     './Public/Uploads/findphoto/'; // 设置附件上传根目录  //  $upload->autoSub = false;//关闭子目录，默认true
          $upload->autoSub = false;
         /* $upload->savePath  =     ''; */// 设置附件上传(子)目录，默认目录名为年月日
                  $info   =   $upload->upload();  // 上传文件 
              if(!$info) {     
                //上传错误提示错误信息
                 $this->error($upload->getError());   
                  }
              else{        
              return $info;
                 }                   
                 }
  public function dolostrelease(){
      $search = D('search');
         if($search->create()){
          if($_FILES['file']['error']==0){
            $logoinfo = $this->MyUpload();
            $pname=$logoinfo['file']['savename'];
          }else{
            $pname = "default.jpg";
          }
          $search->picture=$pname;
       if(false!==$search->add()){
             

          $this->success('添加成功!','pp');
         }
          else{
            $this->error('数据错误');

          } 
           }
          else {            
              $this->error($search->getError());  
                 }  
  

  }
  public function dofindrelease(){
    $find = D('find');
         if($find->create()){
          if($_FILES['file']['error']==0){
            $logoinfo = $this->MUpload();
            $pname=$logoinfo['file']['savename'];
          }else{
            $pname = "default.jpg";
          }
          $find->picture=$pname;
       if(false!==$find->add()){
             

          $this->success('添加成功!');
         }
          else{
            $this->error('数据错误');

          } 
           }
          else {            
              $this->error($find->getError());  
                 }  
  


  }
  public function logout(){
      $_SESSION = array(); //清除SESSION值.
          if(isset($_COOKIE[session_name()])){  //判断客户端的cookie文件是否存在,存在的话将其设置为过期.
                setcookie(session_name(),'',time()-1,'/');
            }
                session_destroy();  //清除服务器的sesion文件
                $this->redirect('fabuqu/pp');
}
}